package jdbc;

import java.sql.*;

/**
 * JDBC java数据库连接
 */
public class JDBCDemo1 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        // 1.注册驱动Class.forName()
        Class.forName("com.mysql.cj.jdbc.Driver");
        // 2.建立连接DriverManager.getConnection()
        String url = "jdbc:mysql://localhost:3307/birdbootdb?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true";
        Connection connection = DriverManager.getConnection(url, "root", "root");
        // 3.创建Statement对象
        Statement statement = connection.createStatement();
        // 4.执行SQL
        String sql = "CREATE TABLE userinfo(" +
                "id INT PRIMARY KEY AUTO_INCREMENT," +
                "username VARCHAR(30)," +
                "password VARCHAR(30)," +
                "nickname VARCHAR(30)," +
                "age INT(3)" +
                ")";
        // 一般用execute()执行DDL查询语句
        statement.execute(sql);
        System.out.println("执行完毕！");
        connection.close();
    }
}
